Last Update: 2025/3/26
Kling Image Generation API
The Kling Image Generation API allows you to create images from textual descriptions using Kling's DALL-E model. This document provides an overview of the API endpoints, request parameters, and response structure.
Endpoint
POST https://platform.llmprovider.ai/v1/images/generations
Request Headers
Header | Value |
---|---|
Authorization | Bearer YOUR_API_KEY |
Content-Type | application/json |
Request Body
The request body should be a JSON object with the following parameters:
Parameter | Type | Description |
---|---|---|
model | string | The model to use for image generation. |
prompt | string | A text description of the desired image(s). |
negative_prompt | string | (Optional) A text description of the undesired images. |
image | string | (Optional) A base64 encoded image or a image url to reference. |
image_fidelity | string | (Optional) Reference strength for user uploaded images during the generation process |
n | integer | (Optional) The number of images to generate. Defaults to 1. |
aspect_ratio | string | (Optional) Aspect ratio of the generated image (width:height ) |
Example Request
{
"model": "kling-img-v1",
"prompt": "A cute baby sea otter",
"n": 1
}
Response Body
The response body will be a JSON object containing the generated images and related metadata.
Field | Type | Description |
---|---|---|
created | integer | The timestamp for when the image was created. |
data | array | An array of generated image objects. |
Example Response
{
"created": 1678891234,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
Example Request
- Shell
- nodejs
- python
curl -X POST https://platform.llmprovider.ai/v1/images/generations \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-img-v1",
"prompt": "A cute baby sea otter",
"n": 1
}'
const axios = require('axios');
const apiKey = 'YOUR_API_KEY';
const url = 'https://platform.llmprovider.ai/v1/images/generations';
const data = {
model: 'kling-img-v1',
prompt: 'A cute baby sea otter',
n: 1
};
const headers = {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
};
axios.post(url, data, { headers })
.then(response => {
console.log('Response:', response.data);
})
.catch(error => {
console.error('Error:', error);
});
import requests
import json
api_key = 'YOUR_API_KEY'
url = 'https://platform.llmprovider.ai/v1/images/generations'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
data = {
'model': 'kling-img-v1',
'prompt': 'A cute baby sea otter',
'n': 1
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print('Response:', response.json())
else:
print('Error:', response.status_code, response.text)
For any questions or further assistance, please contact us at [email protected].